<script setup>
  import { computed, ref } from "vue";
  import useTaskStore from "@/pinia/modules/taskStore";

  const props = defineProps({
    id: {
      type: String,
      required: true,
    },
  });

  const taskStore = useTaskStore();

  /*回单凭证图片*/
  const receiptPictures = ref([]);
  const cargoPickUpPictureList = computed(() => receiptPictures.value.map(item => ({ url: item.url })));

  /*货品图片*/
  const goodsPictures = ref([]);
  const cargoPictureList = computed(() => goodsPictures.value.map(item => ({ url: item.url })));

  /*提交按钮的回调函数*/
  const submit = async () => {
    try {
      await taskStore.takeDelivery({
        id: props.id,
        cargoPickUpPictureList: cargoPickUpPictureList.value,
        cargoPictureList: cargoPictureList.value,
      });
      await uni.reLaunch({ url: "/pages/task/index" });
      uni.showToast({ title: "提货成功", duration: 2000, icon: "error" });
    } catch (error) {
      uni.showToast({ title: error.message, duration: 2000, icon: "error" });
    }
  };
</script>

<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker limit="3" title="请拍照上传回单凭证" v-model="receiptPictures"></uni-file-picker>
      <uni-file-picker limit="3" title="请拍照上传货品照片" v-model="goodsPictures"></uni-file-picker>
    </view>
    <button  class="button" @tap="submit">提交</button>
  </view>
</template>

<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled],
    &.disabled {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
